//
//  SISSJsonRequestNetworkingManager+Registration.m
//  SISSAPP
//
//  Created by 优房网 on 2017/4/21.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSJsonRequestNetworkingManager+Registration.h"
#import "SISSNetworkingManager+File.h"

@implementation SISSJsonRequestNetworkingManager (Registration)

// 3.1.1.1 模糊搜索小区 GET请求
- (void)fuzzySearchHouseResourceCommunityWithKeyword:(NSString *)keyword successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{@"name":keyword};
    
    [MBProgressHUD YYR_HideHUD:YES];
    [SISSPublicSingleton shared].isHud = YES;
    [kJsonRequestNetworkingManager GETWithURLString:URL_HOUSE_RESOURCE_PNAME_LIST parameters:parameters success:^(id responseObject) {
        
        NSLog(@"3.1.1.1 模糊搜索小区: responseObject-->%@",responseObject);
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 3.1.1.2 根据小区获取楼栋列表 GET请求
- (void)requestBuildingResourceWithCommunityName:(NSString *)communityName successBlock:(void (^)(NSArray<SISSBuildingNumberModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{@"name":communityName};
    
    [kJsonRequestNetworkingManager GETWithURLString:URL_HOUSE_RESOURCE_DONG_BNUM_LIST parameters:parameters success:^(id responseObject) {
        
        NSLog(@"3.1.1.2 根据小区获取楼栋列表: responseObject-->%@",responseObject);
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *buildingArr = [NSArray yy_modelArrayWithClass:[SISSBuildingNumberModel class] json:dataArr];
        if (successBlock) {
            successBlock(buildingArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 3.1.1.3 根据楼栋获取房号列表 GET请求
- (void)requestHouseRoomNumberWithBuilding:(NSString *)buildingId successBlock:(void (^)(NSArray<SISSRoomFloorModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{@"dongId":buildingId};
    
    [kJsonRequestNetworkingManager GETWithURLString:URL_HOUSE_RESOURCE_HOUSE_DNUM_LIST parameters:parameters success:^(id responseObject) {
        
        NSLog(@"3.1.1.3 根据楼栋获取房号列表: responseObject-->%@",responseObject);
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *roomNumArr = [NSArray yy_modelArrayWithClass:[SISSRoomFloorModel class] json:dataArr];
        if (successBlock) {
            successBlock(roomNumArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 3.1.1.4 根据房源获取推荐售价 GET请求
- (void)requestHouseEstateHomePageInfoWithCommunityName:(NSString *)communityName successBlock:(void (^)(SISSHouseEstateHomePageInfoModel *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{@"name":communityName};
    
    [kJsonRequestNetworkingManager GETWithURLString:URL_HOUSE_ESTATE_HOME_INFO parameters:parameters success:^(id responseObject) {
        
        NSLog(@"3.1.1.4 根据房源获取推荐售价: responseObject-->%@",responseObject);
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSDictionary *dataDict = responseObject[@"data"];
        
        SISSHouseEstateHomePageInfoModel *model = [SISSHouseEstateHomePageInfoModel yy_modelWithDictionary:dataDict];
        if (successBlock) {
            successBlock(model);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 3.1.1.5 获取房源信息 GET请求
- (void)requestHouseDetailsInfoWithLandId:(NSString *)landId successBlock:(void (^)(SISSHouseDetailsInfoModel *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{@"landId":landId};
    
    [kJsonRequestNetworkingManager GETWithURLString:URL_HOUSE_DETAILS_INFO parameters:parameters success:^(id responseObject) {
        
        NSLog(@"3.1.1.5 获取房源信息 GET请求: responseObject-->%@",responseObject);
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSDictionary *dataDict = responseObject[@"data"];
        
        SISSHouseDetailsInfoModel *model = [SISSHouseDetailsInfoModel yy_modelWithDictionary:dataDict];
        if (successBlock) {
            successBlock(model);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 3.1.1 房源登记
- (void)enrollHouseResourceWithHouseModel:(SISSHouseResourceModel *)houseModel successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSMutableArray *tagArr = [NSMutableArray arrayWithCapacity:houseModel.listTag.count];
    for (int i = 0; i < houseModel.listTag.count; i++) {
        SISSHouseResourceTagModel *model = houseModel.listTag[i];
        
        [tagArr addObject:@{@"tag": model.tag}];
    }
    houseModel.landId = houseModel.landId ? houseModel.landId : @"";
    
    NSDictionary *parameters = @{
                                 @"bnum":houseModel.bnum,
                                 @"dnum":houseModel.dnum,
                                 @"lanId":houseModel.landId,
                                 @"houseInfoNo":houseModel.houseInfoNo,
                                 @"certNo":houseModel.certNo,
                                 @"contractNo":houseModel.contractNo,
                                 @"propertyState":houseModel.propertyState,
                                 @"neighbourhood":houseModel.neighbourhood,
                                 @"region":houseModel.region,
                                 @"regionDetail":houseModel.regionDetail,
                                 @"floor":@(houseModel.floor),
                                 @"totalFloor":@(houseModel.totalFloor),
                                 @"houseType":houseModel.houseType,
                                 @"area":houseModel.area,
                                 @"insideArea":houseModel.insideArea,
                                 @"price":houseModel.price,
                                 @"averagePrice":houseModel.averagePrice,
                                 @"decoration":houseModel.decoration,
                                 @"year":houseModel.year,
                                 @"direction":houseModel.direction,
                                 @"otherdesc":houseModel.otherdesc,
                                 @"phoneNumber":houseModel.phoneNumber,
                                 @"name":houseModel.name,
                                 @"spId":[SISSUserAccount shared].spId,
                                 @"listTag":tagArr.copy
                                 };
    

    [kJsonRequestNetworkingManager POSTWithURLString:URL_ENROLL_HOUSE parameters:parameters success:^(id responseObject) {
        
        NSLog(@"3.1.1 房源登记: responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 3.1.2 客源登记
- (void)enrollPassengerResourceWithHouseModel:(SISSPassengerResourceModel *)passengerModel successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"spId":[SISSUserAccount shared].spId,
                                 @"region":passengerModel.region,
                                 @"regionDetail":passengerModel.regionDetail,
                                 @"neighbourhood":passengerModel.neighbourhood,
                                 @"houseType":passengerModel.houseType,
                                 @"minPrice":@(passengerModel.minPrice),
                                 @"maxPrice":@(passengerModel.maxPrice),
                                 @"minArea":@(passengerModel.minArea),
                                 @"maxArea":@(passengerModel.maxArea),
                                 @"minFloor":@(passengerModel.minFloor),
                                 @"maxFloor":@(passengerModel.maxFloor),
                                 @"decoration":passengerModel.decoration,
                                 @"direction":passengerModel.direction,
                                 @"purpose":passengerModel.purpose,
                                 @"otherdesc":passengerModel.otherdesc,
                                 @"phoneNumber":passengerModel.phoneNumber,
                                 @"name":passengerModel.name,
                                 @"idNumber":passengerModel.idNumber,
                                 @"tag":passengerModel.tag
                                 };

    [SISSPublicSingleton shared].isHud = NO;//
    [kJsonRequestNetworkingManager POSTWithURLString:URL_ENROLL_PASSENGER parameters:parameters success:^(id responseObject) {
        NSLog(@"3.1.2 客源登记: responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 3.2.1 筛选已获得委托未发布合作的房源
- (void)requestHouseCooperationWithparameters:(NSDictionary *)parameters success:(void (^)(NSArray<SISSHouseResourceModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    [kJsonRequestNetworkingManager POSTWithURLString:URL_ENROLL_HOUSE_COOPERATION parameters:parameters success:^(id responseObject) {
        NSLog(@"3.2.1 筛选已获得委托未发布合作的房源: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *houseResourceArr = [NSArray yy_modelArrayWithClass:[SISSHouseResourceModel class] json:dataArr];
        if (successBlock) {
            successBlock(houseResourceArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];

}


// 3.2.2 筛选已获得委托未发布合作的客源
- (void)requestPassengerCooperationWithparameters:(NSDictionary *)parameters success:(void (^)(NSArray<SISSPassengerResourceModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
   
    [kJsonRequestNetworkingManager POSTWithURLString:URL_ENROLL_PASSENGER_COOPERATION parameters:parameters success:^(id responseObject) {
        NSLog(@"3.2.2 筛选已获得委托未发布合作的客源: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
 
        NSArray *houseResourceArr = [NSArray yy_modelArrayWithClass:[SISSPassengerResourceModel class] json:dataArr];
        if (successBlock) {
            successBlock(houseResourceArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}


// 6.1.1 修改线下房源
- (void)updateHouseResourceWithHouseModel:(SISSHouseResourceModel *)houseModel successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    NSMutableArray *tagArr = [NSMutableArray arrayWithCapacity:houseModel.listTag.count];
    for (int i = 0; i < houseModel.listTag.count; i++) {
        SISSHouseResourceTagModel *model = houseModel.listTag[i];
        
        [tagArr addObject:@{@"tag": model.tag}];
    }

    houseModel.landId = houseModel.landId ? houseModel.landId : @"";
    
    NSDictionary *parameters = @{
                                 @"id":houseModel.ID,
                                 @"asoId":houseModel.asoId,
                                 @"bnum":houseModel.bnum,
                                 @"dnum":houseModel.dnum,
                                 @"lanId":houseModel.landId,
                                 @"houseInfoNo":houseModel.houseInfoNo,
                                 @"certNo":houseModel.certNo,
                                 @"contractNo":houseModel.contractNo,
                                 @"propertyState":houseModel.propertyState,
                                 @"neighbourhood":houseModel.neighbourhood,
                                 @"region":houseModel.region,
                                 @"regionDetail":houseModel.regionDetail,
                                 @"floor":@(houseModel.floor),
                                 @"totalFloor":@(houseModel.totalFloor),
                                 @"houseType":houseModel.houseType,
                                 @"area":houseModel.area,
                                 @"insideArea":houseModel.insideArea,
                                 @"price":houseModel.price,
                                 @"averagePrice":houseModel.averagePrice,
                                 @"decoration":houseModel.decoration,
                                 @"year":houseModel.year,
                                 @"direction":houseModel.direction,
                                 @"otherdesc":houseModel.otherdesc,
                                 @"phoneNumber":houseModel.phoneNumber,
                                 @"name":houseModel.name,
                                 @"spId":[SISSUserAccount shared].spId,
                                 @"listTag":tagArr.copy
                                 };
    
    [kJsonRequestNetworkingManager POSTWithURLString:URL_UPDATE_HOUSE parameters:parameters success:^(id responseObject) {
        
        NSLog(@"6.1.1 修改线下房源: responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 6.1.2 更新线下客源
- (void)updatePassengerResourceWithPassengerModel:(SISSPassengerResourceModel *)passengerModel successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"id":passengerModel.ID,
                                 @"neighbourhood":passengerModel.neighbourhood,
                                 @"region":passengerModel.region,
                                 @"regionDetail":passengerModel.regionDetail,
                                 @"minFloor":@(passengerModel.minFloor),
                                 @"maxFloor":@(passengerModel.maxFloor),
                                 @"houseType":passengerModel.houseType,
                                 @"minArea":@(passengerModel.minArea),
                                 @"maxArea":@(passengerModel.maxArea),
                                 @"minPrice":@(passengerModel.minPrice),
                                 @"maxPrice":@(passengerModel.maxPrice),
                                 @"decoration":passengerModel.decoration,
                                 @"direction":passengerModel.direction,
                                 @"otherdesc":passengerModel.otherdesc,
                                 @"purpose":passengerModel.purpose,
                                 @"phoneNumber":passengerModel.phoneNumber,
                                 @"name":passengerModel.name,
                                 @"idNumber":passengerModel.idNumber,
                                 @"spId":[SISSUserAccount shared].spId,
                                 };
    
    [SISSPublicSingleton shared].isHud = NO;//
    [kJsonRequestNetworkingManager POSTWithURLString:URL_UPDATE_PASSENGER parameters:parameters success:^(id responseObject) {
        
        NSLog(@"6.1.2 更新线下客源: responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

#pragma mark - 2.0

// 3.1.3 插入线下出租信息 (图文上传)
- (void)insertLeaseResourceOfflineWithRentOutModel:(SISSRentOutModel *)rentOutModel imagesArray:(NSArray *)imagesArray successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    [kNetworkManager commonUploadFilesWithImages:imagesArray success:^(id  _Nonnull responseObject) {
        
        if ([responseObject[@"code"] integerValue] == 200) {
            NSArray *dataArr = responseObject[@"data"];
            NSDictionary *parameters = @{
                                         @"spId":[SISSUserAccount shared].spId,
                                         @"neighbourhood":rentOutModel.neighbourhood,
                                         @"bnum":rentOutModel.bnum,
                                         @"dnum":rentOutModel.dnum,
                                         @"lanId":rentOutModel.landId.length ? rentOutModel.landId : @"",
                                         @"certificateType":@(rentOutModel.certificateType),
                                         @"propertyNumber":rentOutModel.propertyNumber,
                                         @"unitCode":rentOutModel.unitCode,
                                         @"propertyName":rentOutModel.propertyName,
                                         @"idNumber":rentOutModel.idNumber,
                                         @"mobile":rentOutModel.mobile,
                                         @"lessor":@(rentOutModel.lessor),
                                         @"region":rentOutModel.region,
                                         @"regionDetail":rentOutModel.regionDetail,
                                         @"monthlyRent":rentOutModel.monthlyRent,
                                         @"houseType":rentOutModel.houseType,
                                         @"area":rentOutModel.area,
                                         @"houseConfigure":rentOutModel.houseConfigure,
                                         @"houseFeature":rentOutModel.houseFeature,
                                         @"foregift":rentOutModel.foregift,
                                         @"pay":rentOutModel.pay,
                                         @"floor":rentOutModel.floor,
                                         @"totalFloor":rentOutModel.totalFloor,
                                         @"decoration":rentOutModel.decoration,
                                         @"direction":rentOutModel.direction,
                                         @"otherdesc":rentOutModel.otherdesc,
                                         @"file":dataArr
                                         };
            
            [SISSPublicSingleton shared].isHud = NO;//
            [kJsonRequestNetworkingManager POSTWithURLString:URL_INSERT_LEASE_OFFLINE parameters:parameters success:^(id responseObject) {
                NSLog(@"3.1.3 插入线下出租信息: responseObject-->%@",responseObject);
                if (successBlock) {
                    successBlock(responseObject);
                }
                
            } failure:^(NSError *error) {
                if (failedBlock) {
                    failedBlock(error);
                }
            }];
        }
    } failed:^(NSError * _Nonnull error) {
        NSLog(@"%@",error);
    }];
    
   
}

// 3.1.4 插入线下租客信息
- (void)insertTenantResourceOfflineWithTenantModel:(SISSTenantModel *)tenantModel successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"spId":[SISSUserAccount shared].spId,
                                 @"region":tenantModel.region,
                                 @"regionDetail":tenantModel.regionDetail,
                                 @"neighbourhood":tenantModel.neighbourhood,
                                 @"minPrice":tenantModel.minPrice,
                                 @"maxPrice":tenantModel.maxPrice,
                                 @"houseType":tenantModel.houseType,
                                 @"houseConfigure":tenantModel.houseConfigure,
                                 @"houseFeature":tenantModel.houseFeature,
                                 @"residents":tenantModel.residents,
                                 @"checkinTime":tenantModel.checkinTime,
                                 @"houseConfigure":tenantModel.houseConfigure,
                                 @"houseFeature":tenantModel.houseFeature,
                                 @"decoration":tenantModel.decoration,
                                 @"direction":tenantModel.direction,
                                 @"otherdesc":tenantModel.otherdesc,
                                 @"renterName":tenantModel.renterName,
                                 @"idNumber":tenantModel.idNumber,
                                 @"mobile":tenantModel.mobile
                                 };
    
    [SISSPublicSingleton shared].isHud = NO;//
    [kJsonRequestNetworkingManager POSTWithURLString:URL_INSERT_TENANT_OFFLINE parameters:parameters success:^(id responseObject) {
        NSLog(@"3.1.4 插入线下租客信息: responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

//  6.1.3 修改线下出租
- (void)updateRentOutResourceWithRentOutModel:(SISSRentOutModel *)rentOutModel imagesArray:(NSArray *)imagesArray successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    [kNetworkManager commonUploadFilesWithImages:imagesArray success:^(id  _Nonnull responseObject) {
        if ([responseObject[@"code"] integerValue] == 200) {
            NSArray *dataArr = responseObject[@"data"];
            NSDictionary *parameters = @{
                                         @"id":rentOutModel.ID,
                                         @"spId":[SISSUserAccount shared].spId,
                                         @"certificateType":@(rentOutModel.certificateType),
                                         @"propertyNumber":rentOutModel.propertyNumber,
                                         @"unitCode":rentOutModel.unitCode,
                                         @"propertyName":rentOutModel.propertyName,
                                         @"idNumber":rentOutModel.idNumber,
                                         @"mobile":rentOutModel.mobile,
                                         @"region":rentOutModel.region,
                                         @"regionDetail":rentOutModel.regionDetail,
                                         @"neighbourhood":rentOutModel.neighbourhood,
                                         @"monthlyRent":rentOutModel.monthlyRent,
                                         @"houseType":rentOutModel.houseType,
                                         @"area":rentOutModel.area,
                                         @"houseConfigure":rentOutModel.houseConfigure,
                                         @"houseFeature":rentOutModel.houseFeature,
                                         @"foregift":rentOutModel.foregift,
                                         @"pay":rentOutModel.pay,
                                         @"floor":rentOutModel.floor,
                                         @"totalFloor":rentOutModel.totalFloor,
                                         @"decoration":rentOutModel.decoration,
                                         @"direction":rentOutModel.direction,
                                         @"otherdesc":rentOutModel.otherdesc,
                                         @"file":dataArr
                                         };
            
            [SISSPublicSingleton shared].isHud = NO;//
            [kJsonRequestNetworkingManager POSTWithURLString:URL_UPDATE_OFFLINE_RENT_OUT parameters:parameters success:^(id responseObject) {
                NSLog(@"6.1.3 修改线下出租: responseObject-->%@",responseObject);
                if (successBlock) {
                    successBlock(responseObject);
                }
                
            } failure:^(NSError *error) {
                if (failedBlock) {
                    failedBlock(error);
                }
            }];
        }
    } failed:^(NSError * _Nonnull error) {
        NSLog(@"%@",error);
    }];
}

// 6.1.4 更新线下租客
- (void)updateTenantResourceWithTenantModel:(SISSTenantModel *)tenantModel successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"id":tenantModel.ID,
                                 @"spId":[SISSUserAccount shared].spId,
                                 @"region":tenantModel.region,
                                 @"regionDetail":tenantModel.regionDetail,
                                 @"neighbourhood":tenantModel.neighbourhood,
                                 @"minPrice":tenantModel.minPrice,
                                 @"maxPrice":tenantModel.maxPrice,
                                 @"houseType":tenantModel.houseType,
                                 @"houseConfigure":tenantModel.houseConfigure,
                                 @"houseFeature":tenantModel.houseFeature,
                                 @"residents":tenantModel.residents,
                                 @"checkinTime":tenantModel.checkinTime,
                                 @"houseConfigure":tenantModel.houseConfigure,
                                 @"houseFeature":tenantModel.houseFeature,
                                 @"decoration":tenantModel.decoration,
                                 @"direction":tenantModel.direction,
                                 @"otherdesc":tenantModel.otherdesc,
                                 @"renterName":tenantModel.renterName,
                                 @"idNumber":tenantModel.idNumber,
                                 @"mobile":tenantModel.mobile
                                 };
    
    [SISSPublicSingleton shared].isHud = NO;//
    [kJsonRequestNetworkingManager POSTWithURLString:URL_UPDATE_OFFLINE_TENANT parameters:parameters success:^(id responseObject) {
        NSLog(@"6.1.4 更新线下租客: responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

/// 3.4.1 经纪人业绩申报
- (void)insertAchievementApplyWithParameters:(NSDictionary *)parameters successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    [kJsonRequestNetworkingManager POSTWithURLString:URL_ACHIEVEMENT_APPLY parameters:parameters success:^(id responseObject) {
        
        NSLog(@"3.4.1 经纪人业绩申报: responseObject-->%@",responseObject);
        
        if (successBlock) {
            successBlock(responseObject);
        }
    } failure:^(NSError *error) {
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 3.4.2 获取经纪人业绩申详情 GET请求
- (void)requestAchievementDetailWithID:(NSString *)ID successBlock:(void (^)(SISSKPIDetailModel *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{@"id": ID};
    [kJsonRequestNetworkingManager GETWithURLString:URL_ACHIEVEMENT_DETAIL parameters:parameters success:^(id responseObject) {
        NSLog(@"3.4.2 获取经纪人业绩申详情 GET请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        NSDictionary *dictData = responseObject[@"data"];
        SISSKPIDetailModel *KPIDetailModel = [SISSKPIDetailModel yy_modelWithJSON:dictData];
        if (successBlock) {
            successBlock(KPIDetailModel);
        }
        
    } failure:^(NSError *error) {
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 3.4.3 修改经纪人业绩申报 PUT请求
- (void)updateAchievementApplyWithParameters:(NSDictionary *)parameters successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    [kJsonRequestNetworkingManager PUTWithURLString:URL_UPDATE_ACHIEVEMENT parameters:parameters success:^(id responseObject) {
        
        NSLog(@"3.4.3 修改经纪人业绩申报 PUT请求: responseObject-->%@",responseObject);
        
        if (successBlock) {
            successBlock(responseObject);
        }
    } failure:^(NSError *error) {
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 3.4.4 删除经纪人业绩申报 DELETE请求
- (void)deleteAchievementDetailWithID:(NSString *)ID successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{@"id": ID};
    [kJsonRequestNetworkingManager DELETEWithURLString:URL_DELETE_ACHIEVEMENT parameters:parameters success:^(id responseObject) {
        
        NSLog(@"3.4.4 删除经纪人业绩申报 DELETE请求: responseObject-->%@",responseObject);
        
        if (successBlock) {
            successBlock(responseObject);
        }
    } failure:^(NSError *error) {
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 3.1.3 验证房源编码
- (void)verifyHouseNumWithHouseNum:(NSString *)houseNum roomNum:(NSString *)roomNum successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"validity_no": houseNum,
                                 @"num": roomNum
                                 };
    [kNetworkManager POSTWithURLString:URL_VERIFY_HOUSE_NUM parameters:parameters success:^(id responseObject) {
        NSLog(@"3.1.3 验证房源编码 POST请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failure:^(NSError *error) {
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

/// 3.5.1 模糊搜索机构 GET请求
- (void)fuzzySearchOrganithKeyword:(NSString *)keyword successBlock:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    int type = 1;
    // 判断字符串key是中文还是英文
    NSString *subString = [keyword substringToIndex:1];
    const char *cString = [subString UTF8String];
    if (strlen(cString) == 1) {
        type = 1; // 英文
    } else if (strlen(cString) == 3) {
        type = 2; // 中文
    }

    NSDictionary *parameters = @{
                                 @"key":keyword,
                                 @"type":@(type)
                                 };
    
    [MBProgressHUD YYR_HideHUD:YES];
    [SISSPublicSingleton shared].isHud = YES;
    [kJsonRequestNetworkingManager GETWithURLString:URL_SEARCH_ORGAN parameters:parameters success:^(id responseObject) {
        
        NSLog(@"3.5.1 模糊搜索机构 GET请求: responseObject-->%@",responseObject);
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 3.6.1 获取给房源智能推荐的客源 GET请求
- (void)requestHouseRecommendDemandWithAhrId:(NSString *)ahrId success:(void (^)(NSArray<SISSPassengerResourceModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{@"ahrId" : ahrId};
   
    [kJsonRequestNetworkingManager GETWithURLString:URL_HOUSE_RECOMMEND_DEMAND parameters:parameters success:^(id responseObject) {
        NSLog(@"3.6.1 获取给房源智能推荐的客源 GET请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
 
        NSArray *houseResourceArr = [NSArray yy_modelArrayWithClass:[SISSPassengerResourceModel class] json:dataArr];
        if (successBlock) {
            successBlock(houseResourceArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}


// 3.6.2 获取给客源智能推荐的房源 GET请求
- (void)requestBuyerDemandRecommendHouseWithAbdId:(NSString *)abdId success:(void (^)(NSArray<SISSHouseResourceModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{@"abdId" : abdId};
    
    [kJsonRequestNetworkingManager GETWithURLString:URL_BUYER_DEMAND_RECOMMEND_DEMAND parameters:parameters success:^(id responseObject) {
        NSLog(@"3.6.2 获取给客源智能推荐的房源 GET请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *houseResourceArr = [NSArray yy_modelArrayWithClass:[SISSHouseResourceModel class] json:dataArr];
        if (successBlock) {
            successBlock(houseResourceArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];

}


// 3.6.3 获取给出租智能推荐的租客 GET请求
- (void)requestRentOutRecommendTenantWithAlrId:(NSString *)alrId success:(void (^)(NSArray<SISSTenantModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{@"alrId" : alrId};
    
    [kJsonRequestNetworkingManager GETWithURLString:URL_RENT_OUT_RECOMMEND_TENANT parameters:parameters success:^(id responseObject) {
        NSLog(@"3.6.3 获取给出租智能推荐的租客 GET请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *tenantArr = [NSArray yy_modelArrayWithClass:[SISSTenantModel class] json:dataArr];
        if (successBlock) {
            successBlock(tenantArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}


// 3.6.4 获取给租客智能推荐的出租 GET请求
- (void)requestTenantRecommendRentOutWithArrId:(NSString *)arrId success:(void (^)(NSArray<SISSRentOutModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{@"arrId" : arrId};
    
    [kJsonRequestNetworkingManager GETWithURLString:URL_TENANT_RECOMMEND_RENTOUT parameters:parameters success:^(id responseObject) {
        NSLog(@"3.6.4 获取给租客智能推荐的出租 GET请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *rentOutArr = [NSArray yy_modelArrayWithClass:[SISSRentOutModel class] json:dataArr];
        if (successBlock) {
            successBlock(rentOutArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}


@end
